﻿/* Copyright © 2012 Gargol, Gargol at gbot dot org
   Based on CoreDC Copyright 2007 © Johan Pettersson, Fredrik Johansson, Michael Starberg, Christian Epstein.
 
This file is part of ADCCore.

ADCCore is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.

ADCCore is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with ADCCore.  If not, see <http://www.gnu.org/licenses/>. */
using System;
using System.Collections.Generic;
using System.Text;
using System.Net;


namespace ADCCore.Classes
{
    public class User
    {
        public User()
        {
            this.IP = new IPAddress(0);
            this.Port = 0;
            this.Speed = String.Empty;
            this.ShareSize = 0;
            this.SharedFiles = 0;
            this.Tag = String.Empty;
            this.MaxUploadSpeed = 0;
            this.OpenSlots = 0;
            this.AutoSlot = 0;
            this.MaxOpenSlots = 0;
            this.Email = String.Empty;
            this.Username = String.Empty;
            this.Description = String.Empty;
            this.HubsNormal = 0;
            this.HubsReg = 0;
            this.HubsOP = 0;
            this.HubsStatus = CT.None;
            this.SID = String.Empty;
            this.CID = String.Empty;
            this.Token = String.Empty;
            this.IsOperator = false;
            this.IsHidden = false;
            this.IsBot = false;
            this.IsAway = false;
            this.SupportList = new List<string>();
            this.DownloadList = new List<FileDownload>();
        }
        public enum CT { None = 0, BOT = 1, User = 2, OP = 4, SUser = 8, Owner = 16, Hub = 32 };

        /// <summary>
        /// Gets or sets the users username
        /// </summary>
        /// <value>The username</value>
        public string Username { get; set; }

        /// <summary>
        /// Gets or sets the username to send replies to when recieving a private message. Can be different from Username
        /// </summary>
        /// <value>The username to send replies to</value>
        public string ReplyTo { get; set; }

        /// <summary>
        /// Gets or sets the users IP-address, if known
        /// </summary>
        /// <value>The IP-address</value>
        public IPAddress IP { get; set; }

        /// <summary>
        /// Gets or sets the port the user has open for filetransfers
        /// </summary>
        /// <value>The port</value>
        public int Port { get; set; }

        /// <summary>
        /// Gets or sets the users description, also contains the client-tag
        /// </summary>
        /// <value>The description</value>
        public string Description { get; set; }

        /// <summary>
        /// Gets or sets the users client-tag. Currently always empty, parse tag from Description instead
        /// </summary>
        //public string ClientTag { get; set; }

        /// <summary>
        /// Gets or sets the users transfer (usually upload) speed. Remember that this is a user-set value
        /// </summary>
        /// <value>The speed</value>
        public string Speed { get; set; }

        /// <summary>
        /// Gets or sets the users e-mail address
        /// </summary>
        /// <value>The e-mail adress</value>
        public string Email { get; set; }

        /// <summary>
        /// Gets or sets the size of the users share
        /// </summary>
        /// <value>The sharesize</value>
        public Int64 ShareSize { get; set; }

        /// <summary>
        /// Gets or sets the number of shared files
        /// </summary>
        /// <value>Number of shared files</value>
        public Int64 SharedFiles { get; set; }

        /// <summary>
        /// Gets or sets the flag indicating whether the user is an operator or not in the currently connected hub
        /// </summary>
        /// <value>The operator-flag</value>
        public bool IsOperator { get; set; }
        /// <summary>
        /// Gets or sets the flag indicating whether the user is hidden or not in the currently connected hub
        /// </summary>
        /// <value>The hidden-flag</value>
        public bool IsHidden { get; set; }
        /// <summary>
        /// Gets or sets the flag indicating whether the user is a bot or not in the currently connected hub
        /// </summary>
        /// <value>The bot-flag</value>
        public bool IsBot { get; set; }
        /// <summary>
        /// Gets or sets the flag indicating whether the user is an away or not in the currently connected hub
        /// </summary>
        /// <value>The away-flag</value>
        public bool IsAway { get; set; }


        /// <summary>
        /// Gets or sets the object that contains data about the user
        /// </summary>
        /// <value>The data</value>
        public String Tag { get; set; }

        /// <summary>
        /// Gets or sets the ClientID for the current user
        /// </summary>
        public String SID { get; set; }

        /// <summary>
        /// Gets or sets the ClientID for the current user
        /// </summary>
        public String CID { get; set; }

        /// <summary>
        /// Deep copies the User instance.
        /// </summary>
        public User Clone()
        {
            User u = (User)MemberwiseClone();

            u.IP = new IPAddress(IP.GetAddressBytes());
            return u;
        }

        /// <summary>
        /// Gets or sets the Maximum upload speed bits/s,integer
        /// </summary>
        public int MaxUploadSpeed { get; set; }

        /// <summary>
        /// Gets or sets the minimum number of open slots
        /// </summary>
        public int OpenSlots { get; set; }

        /// <summary>
        /// Gets or sets the speed at wich no more slots should open automatically
        /// </summary>
        public int AutoSlot { get; set; }

        /// <summary>
        /// Gets or sets the maximum open slots in automatic slot manager
        /// </summary>
        public int MaxOpenSlots { get; set; }

        /// <summary>
        /// Gets or sets the number of hubs the users is a regular user in
        /// </summary>
        public int HubsNormal { get; set; }
        /// <summary>
        /// Gets or sets the number of hubs the users is a registered user in
        /// </summary>
        public int HubsReg { get; set; }

        /// <summary>
        /// Gets or sets the number of hubs the users is an operator in
        /// </summary>
        public int HubsOP { get; set; }

        /// <summary>
        /// Gets or sets the token for client-to-client connections
        /// </summary>
        public string Token { get; set; }

        /// <summary>
        /// Gets or sets the status in the current hub.
        /// </summary>
        public CT HubsStatus { get; set; }

        /// <summary>
        /// Starts ClientToClient connection to Current User
        /// </summary>
        public ClientToClient Connect(ADCCore.DcClient client, string token,Int32 port,bool ssl)
        {
            ClientToClient CtC = new ClientToClient();
            CtC.Sender = client;
            CtC.token = token;
            CtC.Connect(this,port,ssl);
            //CtC.user = this;
            return CtC;
        }

        /// <summary>
        /// Get or set the list of files to download
        /// </summary>
        public List<FileDownload> DownloadList { get; set; }

        public List<string> SupportList { get; set; }
    }
}

